SpringBoot官方文档翻译(三):安装部署Spring Boot

10. Installing Spring Boot(安装部署Spring Boot)

1
2
3
4
5
6
7
8
9
Spring Boot can be used with “classic” Java development tools     
or installed as a command line tool. Either way, you need 
Java SDK v1.8 or higher. Before you begin, you should check
your current Java installation by using the following command:
$ java -version
If you are new to Java development or if you want to experiment
with Spring Boot, you might want to try the Spring Boot CLI 
(Command Line Interface) first. Otherwise, read on for “classic”
installation instructions.

Spring Boot 可以被传统的java部署工具部署,也可以被安装为命令行工具。同样的,您需要java1.8或更高的版本支持。在您开始之前,您可以使用如下命令检查一下您的JDK版本

1
$ java -version

如果您是新部署一个应用或者您想尝试下Spring Boot ,您可以首先尝试使用Spring Boot CLI(命令行接口)。否则,请阅读“传统”安装介绍。

10.1 Installation Instructions for the Java Developer(针对java开发者的安装介绍)

1
2
3
4
5
6
7
8
9
10
You can use Spring Boot in the same way as any standard Java library.    
To do so, include the appropriate spring-boot-*.jar files on your
classpath. Spring Boot does not require any special tools integration,
so you can use any IDE or text editor. Also, there is nothing special
about a Spring Boot application, so you can run and debug a
Spring Boot application as you would any other Java program.

Although you could copy Spring Boot jars, we generally recommend
that you use a build tool that supports dependency management (such
as Maven or Gradle).

您可以同样的使用Spring Boot作为一个标准的Java库。因此,您可以讲spring-boot-*.jar适当的引入到您的类路径下。Spring Boot不需要任何特殊的工具集成,因此您可以使用任何IDE或文本编辑器。并且,Spring Boot应用没有任何特殊之处,因此您可以像运行其他任何Java程序一样运行和调试Spring Boot应用程序。尽管您可以拷贝Spring Boot jar包,但我们通常建议您使用支持依赖管理的构建工具(如Maven或Gradle)。

10.1.1 Maven Installation(Maven下的安装)

1
2
Spring Boot is compatible with Apache Maven 3.2 or above. If you do    
not already have Maven installed, you can follow the instructions at maven.apache.org.

Spring Boot与Apache Maven 3.2或更高版本兼容。 如果你
尚未安装Maven,您可以按照maven.apache.org上的说明进行操作。

1
2
3
4
5
On many operating systems, Maven can be installed with a package     
manager. If you use OSX Homebrew, try brew install maven.
Ubuntu users can run sudo apt-get install maven. Windows users
with Chocolatey can run choco install maven from an elevated
(administrator) prompt.

在很多系统中,Maven可以使用包管理器进行安装。如果您使用OSX系统的Homebrew,尝试
brew install maven。Ubuntu用户可以运行 sudo apt-get 安装maven。 具有Chocolatey命令行管理包的Window用户可以以管理员的身份在示框中运行choco install maven

1
2
3
4
5
6
Spring Boot dependencies use the org.springframework.boot groupId.    
Typically, your Maven POM file inherits from the spring-boot-starter-
parentproject and declares dependencies to one or more “Starters”.
Spring Boot also provides an optional Maven plugin to create
executable jars.
The following listing shows a typical pom.xml file:

Spring Boot 依赖使用 org.springframework.boot 作为groupId。通常,您的Maven POM文件继承于spring-boot-starter-parentproject 并且声明依赖于一个或者多个“Straters”。Sring Boot同样提供了可选的Maven插件去创建可运行jars包。以下列表展示了一个通常使用的pom.xml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>

<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
</parent>

<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<!-- Add Spring repositories -->
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>

10.1.2 Gradle Installation(Gradle下的安装)

1
2
3
4
5
6
7
Spring Boot is compatible with Gradle 4. If you do not already    
have Gradle installed, you can follow the instructions at gradle.org.
Spring Boot dependencies can be declared by using the org.springframework.boot group.
Typically, your project declares dependencies to one or
more“Starters”. Spring Boot provides a useful Gradle plugin 
that can be used to simplify dependency declarations and to
create executable jars.

Spring Boot 兼容Gradle 4. 如果您还没有安装Gradle,您可以从 gradle.org中获取介绍文档。
Spring Boot依赖可以被声明为org.springframework.boot group。通常,您的项目被声明依赖于一个或者多个“Strarters”。Spring Boot 提供可用的Gradle 插件用于简化依赖声明和创建可执行jars包。

1
2
3
4
5
Gradle Wrapper
The Gradle Wrapper provides a nice way of “obtaining” Gradle when
you need to build a project. It is a small script and library that
you commit alongside your code to bootstrap the build process.
See docs.gradle.org/4.2.1/userguide/gradle_wrapper.html for details.

Gradle 包装
当您去构建您的应用时,Gradle 包装提供了一个优雅的路径去“获得”Gradle。他提供了一个小脚本和库似的您的提交和构建同步进行。具体参见:docs.gradle.org/4.2.1/userguide/gradle_wrapper.html

1
The following example shows a typical build.gradle file:

以下为一个通常的build.gradle文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
buildscript {
repositories {
jcenter()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.0.BUILD-SNAPSHOT'
}
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

jar {
baseName = 'myproject'
version = '0.0.1-SNAPSHOT'
}

repositories {
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
分享到